#!/usr/bin/env python
"""
qnimbus-qualysguard-scan-python: Requests a scan in QualysGuard, and prints the scan results. Licensed under GNU GPL v3 (http://www.gnu.org/copyleft/gpl.html). Code hosted at qnimbus-qualysguard repository (qnimbus-qualysguard.googlecode.com).

"""
import subprocess
# Set parameters for HTTPS request.
username = 'your_QualysGuard_username'
password = 'your_QualysGuard_password'
# The QualysGuard API server URL depends where your account is located. 
# E.g.: 'qualys.eu' for EU.
qualys_api_server = 'qualys.com'
scanner_appliance = 'scanner_name_to_scan_from'
# Separate words in parameters with a '+' character, not a ' ' (space).
asset_groups = 'asset_group1+asset_group2'
title = 'Qnimbus+cURL+Demo'
# Build query.
query = 'https://%s:%s@qualysapi.%s/msp/scan.php?asset_groups=%s&iscanner_name=%s&scan_title=%s' % (username, password, qualys_api_server, asset_groups, scanner_appliance, title)
# Set curl arguments.
args = [
    'curl',
    '-H', 'X-Requested-With: Qnimbus demo',
    '-D', 'headers',
    query,
]
xml_output = subprocess.check_output(args).decode('utf-8')

# Scan complete. Print scan results.
# Python 3.x command commented out below.
#print(xml_output)
print xml_output